package com.sinopec.resmodule.widget;

import android.graphics.Rect;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.sinopec.basemodule.utils.DensityUtils;

/**
 * author zhanglei
 * date 2018/5/2 14:08
 * description 列表间距
 */
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int horizontalSpace;
    private int verticalSpace;

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.left = DensityUtils.dip2px(horizontalSpace);
        outRect.right = DensityUtils.dip2px(horizontalSpace);
        outRect.bottom = DensityUtils.dip2px(verticalSpace);
        if (parent.getChildAdapterPosition(view) == 0) {
            outRect.top = DensityUtils.dip2px(verticalSpace);
        }

    }

    public SpaceItemDecoration(int horizontalSpace, int verticalSpace) {
        this.horizontalSpace = horizontalSpace;
        this.verticalSpace = verticalSpace;
    }
}